using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_StockManage_DepotListTotal : Member, IRequiresSessionState
{
	private string linkHead = "";
	private string beforeUrl = "DepotListTotal.aspx?1=1";
	private string stockOrderType = "";
	private string stocktypeWhere = "";
	private int productID = 0;
	protected ScriptManager sm;
	protected Literal ltrTitle;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected TextBox txtSearchInfoNumber;
	protected Button btnSearch;
	protected Repeater rptList;
	protected UpdatePanel upList;
	protected Panel pnlManage;
	protected Repeater rptItemInfo;
	protected Literal ltrPagePanel;
	protected Panel pnlDetail;
	public string StockOrderType
	{
		get
		{
			if (base.Request.QueryString["stockType"] != null)
			{
				this.stockOrderType = base.Request.QueryString["stockType"].Trim();
			}
			return this.stockOrderType;
		}
	}
	public string StocktypeWhere
	{
		get
		{
			if (this.StockOrderType != "")
			{
				this.stocktypeWhere = " and  (StockOrderType='" + this.StockOrderType + "') ";
			}
			return this.stocktypeWhere;
		}
	}
	public int ProductID
	{
		get
		{
			if (base.Request.QueryString["ProductID"] != null)
			{
				this.productID = Convert.ToInt32(base.Request.QueryString["ProductID"].Trim());
			}
			return this.productID;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerStockPower(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(base.ActionTabInfo);
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (DisplayName == "checkinfo")
			{
				this.pnlManage.Visible = false;
				this.pnlDetail.Visible = true;
				if (this.StockOrderType == "bad")
				{
					this.ltrTitle.Text = "报损单明细表";
				}
				else
				{
					if (this.StockOrderType == "baoyi")
					{
						this.ltrTitle.Text = "报溢单明细表";
					}
				}
				if (this.ProductID > 0)
				{
					this.InitPage();
				}
				return;
			}
		}
		this.pnlManage.Visible = true;
		this.pnlDetail.Visible = false;
		if (this.StockOrderType == "bad")
		{
			this.ltrTitle.Text = "报损单汇总表";
		}
		else
		{
			if (this.StockOrderType == "baoyi")
			{
				this.ltrTitle.Text = "报溢单汇总表";
			}
		}
		this.txtSearchBeginDate.Text = string.Concat(new object[]
		{
			DateTime.Now.Year,
			"-",
			DateTime.Now.Month,
			"-01"
		});
		this.txtSearchEndDate.Text = DateTime.Now.ToShortDateString();
		this.BindData();
	}
	protected void InitPage()
	{
		string strSQLWhere = string.Concat(new object[]
		{
			" where ",
			this.GetQuery(),
			" and ProductID=",
			this.ProductID
		});
		string orderBy = "order by ProductID desc";
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		int num2 = 10;
		int listInfoItemProductRecordCount = BLLInstance.BllStockInfoOrder.GetListInfoItemProductRecordCount(strSQLWhere);
		int startIndex = (num - 1) * num2 + 1;
		int endIndex = num * num2;
		DataTable listInfoItemProductPage = BLLInstance.BllStockInfoOrder.GetListInfoItemProductPage(strSQLWhere, orderBy, startIndex, endIndex);
		this.rptItemInfo.DataSource = listInfoItemProductPage;
		this.rptItemInfo.DataBind();
		this.linkHead = this.linkHead + "&ProductID=" + this.ProductID;
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string url = string.Concat(new string[]
		{
			this.beforeUrl,
			"&Action=checkinfo&stockType=",
			this.StockOrderType,
			this.linkHead,
			"&pageindex"
		});
		this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, num2, listInfoItemProductRecordCount, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url);
		int num3 = 0;
		decimal d = 0m;
		for (int i = 0; i < this.rptItemInfo.Items.Count; i++)
		{
			HiddenField hiddenField = (HiddenField)this.rptItemInfo.Items[i].FindControl("hfItemPrice");
			HiddenField hiddenField2 = (HiddenField)this.rptItemInfo.Items[i].FindControl("hfItemStockCount");
			Label label = (Label)this.rptItemInfo.Items[i].FindControl("lblItemMoney");
			if (hiddenField != null && hiddenField2 != null)
			{
				if (!string.IsNullOrEmpty(hiddenField.Value) && !string.IsNullOrEmpty(hiddenField2.Value))
				{
					decimal d2 = Convert.ToDecimal(hiddenField.Value);
					int num4 = Convert.ToInt32(hiddenField2.Value);
					decimal d3 = d2 * num4;
					label.Text = d3.ToString();
					num3 += num4;
					d += d3;
				}
			}
		}
		Label label2 = (Label)this.rptItemInfo.Controls[this.rptItemInfo.Controls.Count - 1].FindControl("lblItemFootStockCount");
		Label label3 = (Label)this.rptItemInfo.Controls[this.rptItemInfo.Controls.Count - 1].FindControl("lblItemFootMoney");
		label2.Text = num3.ToString();
		label3.Text = d.ToString();
	}
	protected string GetQuery()
	{
		string text = "OwnerID=" + base.user.UserID + this.StocktypeWhere;
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBeginDate.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and DATEDIFF(DD, StockDate,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchEndDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, StockDate,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("InfoNumber");
		if (!string.IsNullOrEmpty(text4))
		{
			this.txtSearchInfoNumber.Text = text4;
		}
		else
		{
			text4 = this.txtSearchInfoNumber.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and Goods_serial like '%" + text4 + "%'";
			this.linkHead = this.linkHead + "&InfoNumber=" + text4;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by ProductID desc";
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		string text = " from View_JXC_StockOrderInfoItemProduct where ";
		string text2 = "ProductID,ProductName,ProductType,Goods_serial,StockOrderType,Unit,Price";
		string text3 = string.Concat(new string[]
		{
			"ROW_NUMBER() OVER (",
			queryByOrder,
			") as row,",
			text2,
			",SUM(StockCount) as StockCount "
		});
		string sql = string.Concat(new string[]
		{
			"select ",
			text3,
			text,
			query,
			" group by ",
			text2
		});
		DataTable dataTable = this.conn.GetDataTable(sql);
		this.rptList.DataSource = dataTable;
		this.rptList.DataBind();
		int num = 0;
		decimal d = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			HyperLink hyperLink = (HyperLink)this.rptList.Items[i].FindControl("hlGoods_serial");
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfProductID");
			if (hiddenField != null)
			{
				hyperLink.NavigateUrl = string.Concat(new string[]
				{
					"DepotListTotal.aspx?stockType=",
					this.StockOrderType,
					this.linkHead,
					"&Action=checkinfo&ProductID=",
					hiddenField.Value
				});
			}
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfPrice");
			HiddenField hiddenField3 = (HiddenField)this.rptList.Items[i].FindControl("hfStockCount");
			Label label = (Label)this.rptList.Items[i].FindControl("lblMoney");
			if (hiddenField2 != null && hiddenField3 != null)
			{
				if (!string.IsNullOrEmpty(hiddenField2.Value) && !string.IsNullOrEmpty(hiddenField3.Value))
				{
					decimal d2 = Convert.ToDecimal(hiddenField2.Value);
					int num2 = Convert.ToInt32(hiddenField3.Value);
					decimal d3 = d2 * num2;
					label.Text = d3.ToString();
					num += num2;
					d += d3;
				}
			}
		}
		Label label2 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblFootCount");
		Label label3 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblFootMoney");
		label2.Text = num.ToString();
		label3.Text = d.ToString();
	}
	public string GetStatusStr(object obj)
	{
		return BLLInstance.BllStockInfoOrder.GetStockStatusStr(obj);
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		string actionTabInfo = base.ActionTabInfo;
		if (actionTabInfo != null)
		{
			if (actionTabInfo == "checkinfo")
			{
				if (this.ProductID > 0)
				{
					this.InitPage();
				}
				return;
			}
		}
		this.BindData();
	}
}
